;(function(){
var role = require("./role");
var BusCon = require("../../core/bus/_con");
var GoodsCon = require("../../core/goods/_con");
var db = require("../../core/db/index");
var config = require("../../core/_include/config");
var ResponObj = require("../_include/responObj");
module.exports = {
	prefix:"/order",
	post:{
		//财付通支付完成更新定单接口 为后台文件加入不被下载安全目录中
		"/":function(req, res){
            var postdata = this.request.body;
            //效验身份的key码
            if(postdata.pid=='3f310a68ef22309d5bf2398a423df8f1' && postdata.key=='621e2427a7a636a38c4b88fb37b2c47d'){
            	//效验正确
            	var out_trade_no = postdata.out_trade_no;//商品定单号
            	var total_fee = postdata.total_fee;//商品价格
            	total_fee/=100;
            	//获取定单信息
            	var goods = db.find_by_id(config.dbname.ach,out_trade_no);
            	if (goods) {
            		//此处全部效验成功后更新定单状态
            		if(goods.cash==total_fee){
            			//更新定单为支付成功
            			db.update(config.dbname.ach,out_trade_no,[{"dingdan_status":1}]);
                              var PayAchCon = require("../../core/pay_ach/_con");
                              var pay_ach = PayAchCon.get(out_trade_no);
                              pay_ach.endPayAch();
            			this.body = ResponObj("json", goods);
            		}
            	}
			    
            }else{
            	postdata = [{"error":'error_no'}];
            	this.body = ResponObj("json",postdata);
            }
			console.log(out_trade_no);
		}
	}
}	
}());